<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 600px;
            height: 400px;
            border: 1px solid #000;
        }

        .hh {
            width: 100%;
            height: 80px;
            background-color: orange;
            display: flex;
        }

        .hh h1 {
            flex: 1;
            padding-left: 50px;
        }

        .hh span {
            flex: 0.5;
            text-align: center;
            line-height: 80px;
        }

        #xx {
            width: 100%;
            height: 320px;
        }

        #xx img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="hh">
            <h1>陈佳豪</h1>
            <span data-src="./images/1.webp">精选</span>
            <span data-src="./images/2.webp">美食</span>
            <span data-src="./images/3.webp">百货</span>
            <span data-src="./images/4.webp">个护</span>
            <span data-src="./images/5.webp">预告</span>
        </div>
        <div id="xx">
            <img src="./images/4.webp" alt="">
        </div>
    </div>
    <script>
        const tabs = document.querySelector('.hh');
        const preview = document.querySelector('#xx img');
        const defaultSrc = preview.src;

        tabs.addEventListener('mouseover', e => {
            const s = e.target.closest('span');
            if (!s || !tabs.contains(s)) return;
            preview.src = s.dataset.src || defaultSrc;
            tabs.querySelectorAll('span').forEach(x => x.classList.remove('active'));
            s.classList.add('active');
        });

        tabs.addEventListener('mouseleave', () => {
            preview.src = defaultSrc;
            tabs.querySelectorAll('span').forEach(x => x.classList.remove('active'));
        });
    </script>
</body>

</html>